package com.dhy.plugin

import android.os.Bundle
import com.facebook.drawee.backends.pipeline.Fresco
import com.qihoo360.replugin.loader.a.PluginAppCompatActivity
import kotlinx.android.synthetic.main.activity_main.*
import org.jsoup.Jsoup

class PluginActivity : PluginAppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        if (!Fresco.hasBeenInitialized()) Fresco.initialize(this)
        setContentView(R.layout.activity_main)
        button.setOnClickListener {
            parse()
        }
        image.setOnClickListener {
            val url = "https://i1.mifile.cn/a4/xmad_15627254995865_hbFzT.jpg"
            image.setImageURI(url)
        }
    }

    private fun parse() {
        Thread {
            val url = "https://www.baidu.com/"
            val doc = Jsoup.connect(url).get()
            runOnUiThread {
                button.text = doc.select("a").size.toString()
            }
        }.start()
    }
}
